<?php
namespace Home\Controller;
use Think\Controller;
class CartController extends Controller 
{
    public function add()
    {
    	if(IS_POST)
    	{
    		$cartModel = D('Admin/Cart');
    		if($cartModel->create(I('post.'), 1))
    		{
    			if($id = $cartModel->add())
    			{
    				$this->success('添加成功！', U('lst'));
    				exit;
    			}
    		}
    		$this->error('添加失败，原因'.$cartModel->getError());
    	}
    }


    public function lst()
    {
    	$model = D('Admin/Cart');
    	$data = $model->cartList();
		// 设置页面中的信息
		$this->assign(array(
		    'data'=>$data,
			'_page_title' => '购物车列表',
			'_page_keywords' => '购物车列表',
			'_page_description' => '购物车列表',
		));
    	$this->display();
    }
    public function ajaxCartList(){
        $cartModel = D('Admin/Cart');
        $data =$cartModel->cartList();
        echo json_encode($data);
    }

    public function ajaxDelCart(){
        $cartId = I('get.id');
        $cartModel = D('Admin/Cart');
        $cartModel->clearCart($cartId);
    }
    /***********************/
    public function chengeNumber(){
        $cartModel = D('Admin/Cart');
        $cartModel->editGoodsNumber();
        redirect( U( 'Order/add' ) );
    }
    /***********************/
}